// object-utils.ts
export class ObjectUtils {
  /**
   * 深度合并两个对象
   * @param target 目标对象
   * @param source 源对象
   * @returns 合并后的对象
   */
  static deepMerge<T extends Record<string, any>, U extends Record<string, any>>(target: T, source: U): T & U {
    const output = { ...target } as T & U;
    for (const key in source) {
      if (source.hasOwnProperty(key)) {
        if (typeof source[key] === 'object' && typeof target[key] === 'object') {
          output[key] = ObjectUtils.deepMerge(target[key], source[key]) as any;
        } else {
          output[key] = source[key] as any;
        }
      }
    }
    return output;
  }

  /**
   * 检查对象是否为空
   * @param obj 要检查的对象
   * @returns 如果对象为空则返回 true，否则返回 false
   */
  static isEmptyObject(obj: object): boolean {
    return Object.keys(obj).length === 0;
  }

  /**
   * 复制对象
   * @param obj 要复制的对象
   * @returns 复制后的对象
   */
  static copyObject<T extends Record<string, any>>(obj: T): T {
    return JSON.parse(JSON.stringify(obj));
  }
}